package com.bdqn.mr.etl;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.BZip2Codec;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class ETLDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();

        conf.set("mapreduce.map.output.compress","true");
        conf.set("mapreduce.map.output.compress.codec", BZip2Codec.class.getName());

        Job job = Job.getInstance(conf);

        job.setJarByClass(ETLDriver.class);
        job.setMapperClass(ETLMapper.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);
        job.setNumReduceTasks(0);

//        FileInputFormat.setInputPaths(job,new Path(args[0]));
//        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        FileInputFormat.setInputPaths(job, new Path("D:\\mr\\etl\\input"));
        FileOutputFormat.setOutputPath(job,new Path("D:\\mr\\etl\\output"));


        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
